package NetWork;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.Arrays;

public class TestUDP {
    @Test
    public void TestServer() throws IOException {
      DatagramSocket datagramSocket = new DatagramSocket(8080);
      byte[] bytes = new byte[1024];
      DatagramPacket datagramPacket = new DatagramPacket(bytes,0,bytes.length);
      datagramSocket.receive(datagramPacket);
        System.out.println(new String(bytes,0, datagramPacket.getLength()));
      datagramSocket.close();

    }

    @Test
    public void Testclient() throws IOException {
        String s = "hello";
        DatagramSocket datagramSocket = new DatagramSocket();
        DatagramPacket datagramPacket = new DatagramPacket(s.getBytes(),
                s.getBytes().length,
                new InetSocketAddress(InetAddress.getLoopbackAddress(),8080));
        datagramSocket.send(datagramPacket);
        datagramSocket.close();

    }
}
